<template>
  <div class="comment-reply-container">
    <!--    头部信息-->
    <van-nav-bar
      :title="comment.reply_count + '条回复'"
    >
      <van-icon
        slot="left"
        name="cross"
        @click="$emit('close')"
      />
    </van-nav-bar>
    <!--    当前评论-->
    <comment-item :comment="comment" />
    <!--    所有评论回复-->
    <van-cell title="所有回复" />
    <comment-list
      :source="comment.com_id"
      :list="commentList"
      type="c"
    />
    <!--    底部区域-->
    <div class="article-bottom">
      <van-button
        type="default"
        round
        size="small"
        @click="isPostShow = true"
      >写 评 论</van-button>
    </div>
    <van-popup
      v-model="isPostShow"
      position="bottom"
      :style="{ height: '20%' }"
    >
      <post-comment
        :target="comment.com_id"
        :article-id="articleId"
        @post-success="onPostSuccess"
      />
    </van-popup>
  </div>
</template>

<script>
import commentItem from './comment-item'
import commentList from './comment-list'
import postComment from './post-comment'

export default {
  name: 'commentReply',
  components: {
    commentItem,
    commentList,
    postComment
  },
  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      commentList: [] // 评论的回复列表
    }
  },
  methods: {
    onPostSuccess (comment) {
      // 将发布成功的评论放到评论列表顶部
      this.commentList.unshift(comment)
      // 更新评论的回复数量
      this.comment.reply_count++
      // 关闭发布回复的弹出窗
      this.isPostShow = false
    }
  }
}
</script>

<style scoped>
.comment-reply-container {
  padding-top: 46px;
  padding-bottom: 44px;
}
.van-nav-bar {
  background-color: #FFF;
  position: fixed;
  top: 20%;
  left: 0;
  right: 0;
}
/deep/ .van-nav-bar__title {
  color: #323233;
}
.article-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-sizing: border-box;
  height: 44px;
  border-top: 1px solid #d8d8d8;
  background-color: #fff;
}
.article-bottom .van-button {
  width: 60%;
}
</style>
